package farb.top.eurekaclientriskapp.repo;

import com.alibaba.fastjson2.JSON;
import farb.top.eurekaclientriskapp.model.Risk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

@Repository
public class RedisRiskRepo {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void saveRiskLevel(String key, int expireTime, Risk risk) {
        redisTemplate.opsForValue().set(key, JSON.toJSONString(risk), expireTime, TimeUnit.MINUTES);
    }

    public Risk getRiskLevel(String key) {
        String json = redisTemplate.opsForValue().get(key);
        return JSON.parseObject(json, Risk.class);
    }
}
